package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.entity.User;

/**
 * Created by yinyonggang on 2018/7/25.
 */
@RestController
@RequestMapping("feigns")
public class DemoController {

	@RequestMapping(value = "/getRequest", method = RequestMethod.GET)
	public String getRequest() {
		String str = "我是服务提供方get请求";
		System.out.println(str);
		return str;
	}
	
	@RequestMapping(value = "/postRequest", method = RequestMethod.POST)
	public String postRequest() {
		String str = "我是服务提供方post请求";
		System.out.println(str);
		return str;
	}
	
	/**
	 * post请求带参数
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "/postRequestByParam", method = RequestMethod.POST)
	public String postRequestByParam(@RequestBody(required = false) User user) {
		//这个sleep是为了测试 feign调用的时候断路由是否成功 [其实也可以直接将该服务停止掉]
		/*try {
			Thread.sleep(100000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}*/
		String postParam = user.getName() + "--:--" + user.getAge();
		System.out.println(postParam);
		return postParam;
	}
	
	/**
	 * requestParam
	 * @param pageNum
	 * @return
	 */
	@RequestMapping(value = "/requestParam", method = RequestMethod.POST)
	public int requestParam(@RequestParam(value = "pageNum") int pageNum) {
		System.out.println(pageNum);
		return pageNum;
	}
}
